import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push

//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [{
  path: '',
  redirect: '/home',
  name: 'Layout',
  component: () => import('../views/layout/index.vue'),
  children: [{
    path: '/home',
    component: () => import('../views/home/Home.vue')
  }, {
    path: '/published',
    component: () => import("../views/article/Published.vue")
  }, {
    path: '/article/:id',
    component: () => import('../views/article/Detail.vue')
  }]
}, {
  path: '/login',
  name: "Login",
  component: () => import("../views/login/Login.vue")
}, {
  path: '/register',
  name: 'Register',
  component: () => import("../views/login/Register.vue")
}]

const router = new VueRouter({
  routes
})

export default router